package com.zbec.mdrs.web;

import com.zbec.framework.core.vo.JqgridResponse;
import com.zbec.framework.core.vo.PageInfo;
import com.zbec.framework.security.service.SecurityService;
import com.zbec.mdrs.service.*;
import com.zbec.mdrs.vo.ReportFileVo;
import com.zbec.mdrs.vo.ReportTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by fxl on 2015/10/28.
 */
@Controller
@RequestMapping(value = "/task")
public class ReportTaskController extends  BaseController {


    @Autowired
    private ReportTaskService reportTaskService;

    @Autowired
    private ReportFileService reportFileService;

    @Autowired
    private SecurityService securityService;


    @RequestMapping(value = "/toTask")
    public String toReport(HttpServletRequest request) {
        if(this.isUserReseted(securityService.getCurrentUserVO())){
            return "system/editPassword";
        }else{
            return "task/task_list";
        }
    }

    @RequestMapping(value = "/toDetail")
    public ModelAndView toDetail(ReportTaskVo vo,HttpServletRequest request) {
        ModelAndView view=new ModelAndView("task/task_view");
        view.addObject("id",vo.getId());
        return view;
    }

    @RequestMapping(value = "/taskList")
    @ResponseBody
    public JqgridResponse<ReportTaskVo> findAllReportTask(PageInfo pageInfo,HttpServletRequest request) {
        return reportTaskService.findAllTask(pageInfo);
    }
    @RequestMapping(value = "/viewList")
    @ResponseBody
    public JqgridResponse<ReportFileVo> findFileByTaskId(ReportTaskVo vo,PageInfo pageInfo,HttpServletRequest request) {
        return reportFileService.findFileByTaskId(vo.getId(),pageInfo);
    }

}
